<?php
// check user login 
//
// digiboard by digitalboom.org
// http://www.digitalboom.org
//
// Information Technology program
// Sirindhorn International Institute of Technology
// Thammasat University, Rangsit Campus
// http://www.siit.tu.ac.th
//
// authors: some seniors ?,sea
// first created on: 2002 Mar 10
// last modified on: 2008 May 24
// last modified by: sea

include("settings/config.inc.php");
include("settings/accounts.inc.php");
include("settings/forum.inc.php");
include("lib/util.inc.php");
include("lib/users_function.inc.php");
include("lib/sh.inc.php");

global $db_link, $DGB;

extract($_POST);
extract($_GET);

$error_message = "";   

if (empty($Username)) {
 $error_message.="##  Please add your Username\\n";
}

if (empty($Password)) {
 $error_message.="##  Please add your password\\n";
}

if (!empty($error_message)) {
 $javatext = "<script language='JavaScript'>alert('Please complete your detail :\\n$error_message'); history.back();</Script>";
 echo $javatext;
 exit;
}

addslashes($Username);
shad2pw($Password);
$AlreadyLogin = CheckUser($Username,$Password,$db_link,$DGB["DB_USERS_TABLE"]);

if ($AlreadyLogin == 1) {
 //Keep me login
 if ($remember){
	 setcookie("Username",$Username,time()+9999999);
	 setcookie("Password",$Password,time()+9999999);
 }else{
	 setcookie("Username",$Username);
	 setcookie("Password",$Password);
 }
 $_COOKIE["Username"] = $Username;
 $_COOKIE["Password"] = $Password;

 Header("Location: list.php");
} else {
 $javatext = "<script language='JavaScript'>alert('Incorrect Login or Password :\\n'); history.back();</Script>";
 echo $javatext;
 exit;
}
?>
